<template>
	<view>

		<button v-if="is_style=='button'" class="flex j-c a-c b_y cff but_login" style="background-color: #00A0E9;"
			open-type="getUserInfo" @getuserinfo="bindGetUserInfo">
			<text>QQ授权登录</text>
		</button>


		<view v-if="is_style=='img'"> 
			<button open-type="getUserInfo" @getuserinfo="bindGetUserInfo">
				<image class="q_y login_icon" src="@/static/icon/qq.png"></image>
			</button>
		</view>
	</view>
</template>

<script>
	export default {
		name: "login-mp-qq",
		props: {
			userName: {
				type: String,
				default: ''
			},
			avatarUrl: {
				type: String,
				default: ''
			},
			agr: {
				type: Boolean,
				default: false
			},
			agr: {
				type: Boolean,
				default: false
			},
			is_style: {
				type: String,
				default: 'button'
			},
		},
		data() {
			return {}
		},
		created() {
			this.face = this.avatarUrl;
			this.nickname = this.userName;
		},
		methods: {
			bindGetUserInfo(e) {
			 
				let that = this;
				if (!this.agr) {
					uni.showToast({
						title: '请勾选同意协议',
						icon: "none"
					});
					return;
				}
				uni.showLoading({
					title: '正在登录中...',
					mask: true
				})
				//qq小程序授权登录
				that.nickname = e.target.userInfo.nickName;
				that.face = e.target.userInfo.avatarUrl;
	 
				that.qq_login();

				// uni.getUserInfo({
				// 	// 获取信息成功
				// 	success(res) {
				// 		console.log(res)
				// 		that.nickname = res.userInfo.nickName;
				// 		that.face = res.userInfo.avatarUrl;

				// 		that.qq_login();
				// 	},
				// 	fail(err) {
				// 		uni.showToast({
				// 			icon: 'none',
				// 			title: '授权失败，请重试'
				// 		})
				// 	}
				// });
			},
			//qq小程序登录
			qq_login() {
				let that = this;
				uni.login({
					provider: 'qq',
					success: function(loginRes) {
						let code = loginRes.code;
						let requestParams = {
							face: that.face,
							nickname: that.nickname,
							qq_code: code,
							sex: 0,
							tel: '',
							checknum: '',
						};

						that.Banmikeji.qq_login(requestParams).then(ret => {
							console.log("ret11: " + JSON.stringify(ret));
							that.$emit('confirm', ret);
						})

					},
				});
			},

		}
	}
</script>
<style lang="scss">
	.but_login {
		width: 600rpx;
		height: 80rpx;
		background-color: #1DC069;
	}
	
	button::after {
		border: none;
	}
	
	button {
	
		border: 0;
		padding: 0;
		background-color: transparent;
	
	}
</style>